import { defineStore } from 'pinia'
import { getInfo } from '@api/user'
import {  Role } from '@interface/user'
export const useUserStore = defineStore('userId', {
  state: () => {
    return {
      roles:[],
      rolePerm:'',
      permissions:"",
      units:"",
      userInfo:"",
    }
  },
  getters:{},
  actions:{
    async getUserInfo(){
      let res = await getInfo();
      let { permissions , roles, units , userInfo } = res.data;
      //角色信息
      this.roles = roles;
      this.permissions = permissions;
      this.units = units;
      this.userInfo = userInfo;
      this.rolePerm = roles[0].rolePerm;
    }
  },
  persist: {
    enabled: true, //开启数据缓存
    strategies: [
      {
        storage: localStorage,//默认走session
        paths: ['rolePerm']
      }
    ]
  }
})